package speelotheek.components;

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;

import speelotheek.views.Credits;


public class Frame extends JFrame 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6596737848110215497L;
	protected boolean fullscreen = false;
	
	/**
	 * Create the frame.
	 */
	public Frame() 
	{
		setResizable(true);
		setIconImage(Toolkit.getDefaultToolkit().getImage(Frame.class.getResource("/speelotheek/resources/tag_48.png")));
		setTitle("Speel-o-theek Klapstuk");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1024, 768);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnMenu = new JMenu("Menu");
		menuBar.add(mnMenu);
		
		JMenuItem mntmVolledigScherm = new JMenuItem("Volledig Scherm");
		mntmVolledigScherm.setIcon(new ImageIcon(Frame.class.getResource("/speelotheek/resources/photos_32.png")));
		mnMenu.add(mntmVolledigScherm);
		mntmVolledigScherm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if(fullscreen == false) {
					setExtendedState(Frame.MAXIMIZED_BOTH);
					fullscreen = true;
				}
				else {
					setExtendedState(Frame.NORMAL);
					fullscreen = false;
				}
				
			}
		});
		
		JMenuItem mntmInfo = new JMenuItem("Credits");
		mntmInfo.setIcon(new ImageIcon(Frame.class.getResource("/speelotheek/resources/books_32.png")));
		mnMenu.add(mntmInfo);
		mntmInfo.addActionListener(new ActionListener() {			
			@Override
			public void actionPerformed(ActionEvent e) {
				Credits info = new Credits();
				info.setVisible(true);
			}
		});
		
		JMenuItem mntmExit = new JMenuItem("Afsluiten");
		mntmExit.setIcon(new ImageIcon(Frame.class.getResource("/speelotheek/resources/cross_32.png")));
		mnMenu.add(mntmExit);
		mntmExit.addActionListener(new ActionListener() {			
			@Override
			public void actionPerformed(ActionEvent e) {
				Database.closeConnection();
				setVisible(false);
				dispose();	
		        System.exit(0);
			}
		});
	}

}
